﻿using System.Collections.Generic;
using System.Xml.Serialization;

namespace UnknowWorld.CardGame
{
    [System.Serializable]
    public class Character
    {
        /// <summary>
        /// 最大生命
        /// </summary>
        public int MaxHealth { get; set; }
        /// <summary>
        /// 当前生命
        /// </summary>
        public int Health { get; set; }
        /// <summary>
        /// 最大魔力
        /// </summary>
        public int MaxMagic { get; set; }
        /// <summary>
        /// 当前生命
        /// </summary>
        public int Magic { get; set; }
        /// <summary>
        /// 最大耐力
        /// </summary>
        public int MaxStamina { get; set; }
        /// <summary>
        /// 当前生命
        /// </summary>
        public int Stamina { get; set; }
        /// <summary>
        /// 手牌数量
        /// </summary>
        public int HandCardCount { get; set; }
        /// <summary>
        /// 拥有的卡牌Key
        /// </summary>
        public List<Card> Cards { get; set; }

        /// <summary>
        /// 受到伤害时
        /// </summary>
        [XmlIgnore]
        public System.Action<int> OnHurt { get; set; }
        /// <summary>
        /// 魔法能量消耗时
        /// </summary>
        [XmlIgnore]
        public System.Action<int> OnExpandMagic { get; set; }
        /// <summary>
        /// 耐力能量消耗时
        /// </summary>
        [XmlIgnore]
        public System.Action<int> OnExpandStama { get; set; }

        /// <summary>
        /// 受到伤害
        /// </summary>
        /// <param name="value"></param>
        public void Hurt(int value)
        {
            int v = Health - value;
            Health = v < 0 ? 0 : v;
            if (null != OnHurt) OnHurt(value);
        }

        /// <summary>
        /// 能量消耗
        /// </summary>
        /// <param name="value"></param>
        /// <param name="type"></param>
        public void ExpandEnergy(int value, EnergyType type)
        {
            switch (type)
            {
                case EnergyType.Magic:
                    int v = Magic - value;
                    Magic = v < 0 ? 0 : v;
                    if (null != OnExpandMagic) OnExpandMagic(v);
                    break;
                case EnergyType.Stamina:
                    v = Stamina - value;
                    Stamina = v < 0 ? 0 : v;
                    if (null != OnExpandStama) OnExpandStama(v);
                    break;
            }
        }
        /// <summary>
        /// 能量是否充足
        /// </summary>
        /// <param name="value"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public bool EnoughEnergy(int value, EnergyType type)
        {
            bool enough = false;
            switch (type)
            {
                case EnergyType.Magic:
                    enough = Magic >= value;
                    break;
                case EnergyType.Stamina:
                    enough = Stamina >= value;
                    break;
            }
            return enough;
        }
    }
}